<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!-- import CSS -->
    <link rel="stylesheet" href="https://cdn.staticfile.org/element-ui/2.15.9/theme-chalk/index.css">
    <style>
        .center {
            width: 1200px;
            margin: 0 auto;
        }

        #footer_center p {
            margin: 0;
        }

        #footer_center h3 {
            color: white;
        }

        body {
            background-color: rgb(241, 242, 243);
        }

        .el-header {
            background-color: white;
        }
        .title-p{
            height: 40px;
            overflow: hidden;
            display: -webkit-box;
            -webkit-line-clamp: 2;
            -webkit-box-orient: vertical
        }
    </style>
</head>
<body>
<div id="app">
    <el-container>
        <my-header></my-header>
        <el-main class="center">
            <!--内容列表开始-->
            <el-row gutter="20">
                <el-col v-for="r in contentArr" span="6">
                    <el-card style="margin: 10px 0">
                        <a style="color: #333;text-decoration: none"
                           :href="'/detail.html?id='+r.id">
                        <img :src="r.imgUrl" width="100%" height="144">
                        <p class="title-p">{{r.title}}</p>
                        </a>
                        <el-row gutter="20">
                            <el-col span="4">
                                <!--圆形图片,专门用来显示头像-->
                                <el-avatar size="small" :src="r.userImgUrl"></el-avatar>
                            </el-col>
                            <el-col span="10">{{r.nickName}}</el-col>
                            <el-col span="10">
                                <span style="float: right;font-size: 12px;color: #ccc">{{r.categoryName}}</span>
                            </el-col>
                        </el-row>
                    </el-card>
                </el-col>
            </el-row>
            <div style="text-align: center;margin-bottom: 20px">
                <el-button>点击查看更多内容</el-button>
            </div>
            <!--内容列表结束-->
        </el-main>
        <el-footer style="height: 280px;background-color: #2f3234;padding:50px 0">
            <my-footer></my-footer>
        </el-footer>
    </el-container>
</div>
</body>
<!-- import Vue before Element -->
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<!-- import JavaScript -->
<script src="https://cdn.staticfile.org/element-ui/2.15.9/index.min.js"></script>
<!--引入Axios-->
<script src="https://cdn.bootcss.com/axios/0.18.0/axios.min.js"></script>
<!--引入自己的js文件-->
<script src="js/my-header.js"></script>
<script src="js/my-footer.js"></script>
<script>
    let v = new Vue({
        el: '#app',
        data: function () {
            return {
                contentArr: []
            }
        },
        methods: {},
        created: function () {
            //判断地址栏中是否包含type
            if (location.search.includes("type")) {
                let type = location.search.split("=")[1];
                //通过type请求相关的内容
                axios.get("/v1/contents/" + type + "/list").then(function (response) {
                    if (response.data.code == 1) {
                        v.contentArr = response.data.data;
                    }
                })
            }
            //判断是否包含wd
            if (location.search.includes("wd")){
                let wd = new URLSearchParams(location.search).get("wd");
                //请求和wd关键字相关的内容
                axios.get("/v1/contents/"+wd+"/search").then(function (response) {
                    if (response.data.code==1){
                        v.contentArr = response.data.data;
                    }
                })

            }

        }
    })
</script>
</html>